class EventCenterManager {
    private _messages: any;
    private dispathcer: egret.EventDispatcher = new egret.EventDispatcher();
    private static _instance: EventCenterManager;
    public static getInstance() {
        if (!this._instance) {
            this._instance = new EventCenterManager();
        }
        return this._instance;
    }

    /**
     * 构造函数
     */
    public constructor() {
        this._messages = {};
    }

    /**
     * 清空处理
     */
    public clear(): void {
        this._messages = {};
    }

    /**
     * 注册本模块消息
     * @param key 唯一标识
     * @param callbackFunc 侦听函数
     * @param callbackObj 侦听函数所属对象
     */

    public register(type: string, listener: Function, thisObject: any, useCapture?: boolean, priority?: number): void {
        this.dispathcer.addEventListener(type, listener, thisObject, useCapture, priority);
    }

    /**
     * 动态移除Controller
     * @param key 唯一标识
     *
     */
    public unregister(type: string, listener: Function, thisObject: any, useCapture?: boolean): void {
        this.dispathcer.removeEventListener(type, listener, thisObject, useCapture);
    }


    public dispatchEvent(event: egret.Event) {
        this.dispathcer.dispatchEvent(event);
    }

    /**
     * 触发本模块消息
     * @param key 唯一标识
     * @param param 所需参数
     *
     */
    public dispatch(name: string, data?: any): any {
        let evt: egret.Event = new egret.Event(name);
        evt.data = data;
        this.dispathcer.dispatchEvent(evt);
    }
}
